<!DOCTYPE HTML>
<html>
<head>
    <title>部落管理</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 98%">
<div class="mini-splitter" style="width:100%;height:100%;">
    <div size="170" showCollapseButton="true">
        <div class="mini-fit">
            <ul id="tree1" class="mini-tree"  url="/getdata/parentGoodsTypeTreeWithoutParent" style="width:100%;"
                showTreeIcon="true" textField="name" idField="id" value="0" parentField="pid" resultAsTree="false"
            >
            </ul>
        </div>
    </div>
    <div showCollapseButton="true">
        <div id="outImg">
            <img id="imgId" src="" alt="" onclick="smallImg()">
        </div>

        <div style="width:99%;">
            <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <a class="mini-button" iconCls="icon-add" onclick="classAdd()">增加</a>
                            <a class="mini-button" iconCls="icon-edit" onclick="classEdit()">编辑</a>
                            <a class="mini-button" iconCls="icon-remove" onclick="classRemove()">删除</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>

        <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 48%;"
             url="/getdata/fetchGoodsTypeBanners" idField="id" allowResize="true" onselectionchanged="onSelectionChanged"
             sizeList="[20,30,50,100]" pageSize="20"
        >
            <div property="columns">
                <div type="checkcolumn" width="20" ></div>
                <div field="objectId" width="80" align="center" headerAlign="center">objetID</div>
                <div field="name" width="80" align="center" headerAlign="center">分类名称</div>
                <div field="picURL"  width="30" align="center" headerAlign="center">banner图</div>
                <div field="sort" width="40" align="center" headerAlign="center" >排序</div>
             </div>
        </div>

        <div style="width:99%;">
            <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <a class="mini-button" iconCls="icon-add" onclick="goodsAdd()">增加</a>
                            <a class="mini-button" iconCls="icon-remove" onclick="goodsRemove()">删除</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div id="datagrid2" class="mini-datagrid" style="width:99%;height:37%;" url="/getdata/fetchBannerRelationGoods"
             sizeList="[20,30,50,100]" pageSize="20"  allowResize="true">
            <div property="columns">
                <div type="checkcolumn" width="15" ></div>
                <div field="objectId" width="60" align="center" align="center" headerAlign="center">Id</div>
                <div field="goodsId" width="60" align="center" align="center" headerAlign="center">关联商品Id</div>
                <div field="goodsName" width="60" align="center" align="center" headerAlign="center">商品名</div>
                <div field="sort" width="40" align="center" headerAlign="center" >序号</div>

            </div>
        </div>
    </div>

</div>
</body>
<script type="text/javascript">
    var flag = 1;
    var bannerOId;
    var objectId = "1";
    var tribeName;
    mini.parse();
    var tree = mini.get("tree1");
    var grid = mini.get("datagrid1");
    var grid2 = mini.get("datagrid2");
    tree.on("nodeselect", function (e) {
        if (e.isLeaf) {
            objectId=e.node.objectId;
             grid.load({ type: objectId });
            grid2.setData([]);
            grid2.setTotalCount(0);
        } else {
            grid.setData([]);
            grid.setTotalCount(0);
        }
        bannerOId = null;
    });
    grid.load({type:objectId});
    grid.on("drawcell", function (e) {
        var value = e.value;
        var column = e.column;
        if (column.field == "picURL") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
    });

    function search() {
        var typeName = mini.get("typeName").getValue();
        var objectId = mini.get("objectId").getValue();
        grid.load({
            typeName: typeName,
            objectId:objectId,
            type:objectId
        });

    }
    function searchStatus() {
        var status = mini.get("status").getValue();
        grid.load({
            status: status
        });
    }
    $("#name,#objectId,#creater,#nickName，#numNumber").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });

    function classAdd() {
        mini.open({
            url: "/getdata/banner/addBanner?objectId="+objectId,
            title: "新增Banner", width: 550, height: 200,
            onload: function () {
            },
            ondestroy: function (action) {
                bannerOId = '';
                grid.reload();
                grid2.setData([]);
                grid2.setTotalCount(0);
            }
        });
    };
    function classEdit() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "/getdata/banner/editBanner?objectId="+row.objectId,
                title: "编辑Banner", width: 550, height: 200,
                onload: function () {
                },
                ondestroy: function (action) {
                    bannerOId = '';
                    grid.reload();
                    grid2.setData([]);
                    grid2.setTotalCount(0);
                }
            });
        } else {
            alert("请选中一条记录");
        }
    };
    function classRemove() {
        var row = grid.getSelected();
        if (row) {
            var objectId = row.objectId;
                $.ajax({
                    url: "/getdata/banner/removeGoodsBanner",
                    type: 'post',
                    data: {
                        objectId:objectId,
                    },
                    cache: false,
                    success: function (result) {
                        if (result == 10000){
                            bannerOId = '';
                            grid.reload();
                        } else {
                            alert('删除失败，请重试！');
                            return;
                        }
                    },
                    error: function (error) {
                        console.log(error)
                    }
                });

        } else {
            alert("请选中一条记录");
        }
    };

    function bigImg() {
        var row = grid.getSelected();
        if (row) {
            var path = row.picURL;
             $("#imgId").attr('src', path);
            $("#outImg").css('display','block');
        }
    }
    function bigImgCode() {
        var row = grid.getSelected();
        if (row) {
            if(flag==1) {
                var path = row.qrCode;
                $("#imgId").attr('src', path);
                $("#outImg").css('display','block');
            }
        }
    }
    function smallImg() {
        $("#outImg").css('display','none');
    }


    function onBirthdayRenderer(e) {
        var value = e.value;
        if (value) return mini.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
        return "";
    };

    function onSelectionChanged(e) {
        var tribeGrid = e.sender;
         var record = tribeGrid.getSelected();
        if (record) {
            bannerOId = record.objectId;
            tribeName = record.name;
            grid2.load({goodsBannerOId:record.objectId});
        }
    }

    grid2.on("drawcell", function (e) {
        var value = e.value;
        var column = e.column;
        if (column.field == "picName") {
            if (value) {
                e.cellHtml = '<img class="bigImg" onclick="userBigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
            } else {
                e.cellHtml = '<img class="bigImg" onclick="userBigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }

        if (column.field == "userQrCode") {
            if (value) {
                e.cellHtml = '<img class="bigImg" onclick="userBigImgCode()" src="' + value + '" width="30" height="30" alt="图片">';
            } else {
                e.cellHtml = '<img class="bigImg" onclick="userBigImgCode()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }

    });
    function userBigImg() {
        var row = grid2.getSelected();
        if (row) {

            var path = row.picName;
            $("#imgId").attr('src', path);
            $("#outImg").css('display','block');

        }
    };
    function userBigImgCode() {
        var row = grid2.getSelected();
        if (row) {
            if(flag==1) {
                var path = row.userQrCode;
                $("#imgId").attr('src', path);
                $("#outImg").css('display','block');
            }
        }
    };

    function searchMembers() {
        var nickName = mini.get("memberName").getValue();
        var userOId = mini.get("memberId").getValue();
        var userType = mini.get("memberType").getValue();

            grid2.load({
                tribeOId:tribeOId,
                nickName: nickName,
                userOId:userOId,
                userType:userType,
            });
    }
    $("#tribeId,#memberName,#memberId,#memberType").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            searchMembers();
        }
    });
    function onSelectedChanged(e) {
        var tribeMemberGrid = e.sender;
        var record = tribeMemberGrid.getSelected();
        if (record) {
            userOId = record.userOId;
        }
    };
    function goodsAdd() {
        if (bannerOId == "" || bannerOId == undefined || bannerOId == null){
            alert('请先选择一个分类');
            return;
        };
        mini.open({
            url: "/getdata/addBannerRelationGoods?bannerOId="+bannerOId,
            title: "添加商品", width: 500, height: 300,
            onload: function () {
            },
            ondestroy: function (action) {

                grid2.reload();
            }
        });
    };
    function goodsRemove() {
        var row2 = grid2.getSelected();
        if (row2) {
            var objectId = row2.objectId;
             $.ajax({
                url: "/getdata/banner/removeBannerRelationGoods",
                type: 'post',
                data: {
                    objectId:objectId
                 },
                cache: false,
                success: function (result) {
                    if (result == 10000){
                        grid2.reload();
                    } else {
                        alert('删除失败，请重试！');
                        return;
                    }
                },
                error: function (error) {
                    console.log(error)
                }
            });

        } else {
            alert("请选中一条记录");
        }
    };
</script>
</html>
